document.querySelector('#top_out').onclick = function () {
    document.querySelector('#index_wirBlog_box').style.display = 'none';
    document.querySelector('#index_top_box').style.display = '';
    document.querySelector('#index_content_box').style.display = '';
    document.querySelector('#index_details_box').style.display = 'none';

}

document.getElementById('fabu').addEventListener('click', function () {
    // 发布
    let title = document.querySelector('#titile_input').value.trim();
    // let titleflag=title.trim();
    if (title) {
        release(editor.txt.text(), editor.txt.html(), title)
    } else {
        alert("标题必须写")
    }


}, false)

function release(text, htmltext, title) {
    let u_id = JSON.parse(localStorage.getItem("u_id"))

    let imgSrcS = imgUrl(htmltext)
    imgSrcS = JSON.stringify(imgSrcS)
    future.ajax({
        url: '/article/release',
        type: 'post',
        data: {
            text,
            htmltext,
            u_id,
            imgSrcS: imgSrcS,
            title
        },
        success: function (result) {
            alert("发布成功,返回主页面")
            // window.location.href = "../../index0.html"

            document.querySelector('#index_wirBlog_box').style.display = 'none';
            document.querySelector('#index_top_box').style.display = '';
            document.querySelector('#index_content_box').style.display = '';
            document.querySelector('#index_details_box').style.display = 'none';

            console.log(result)
        }
    })

}

/**
 * 截取html文本中img属性
 * @param string
 * @returns {Array}
 */
function imgUrl(string) {
    var a = string;
    var arrimg = [];
    a.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
        arrimg.push(capture);
    });
    if (arrimg != null && arrimg.length > 0) {
        return arrimg;
    }
}